<?php
/**
 *
 * User: chenzheng
 * Date: 2023/4/4
 * Time: 15:37
 */

namespace app\api\library\index\goodsDetail;

use app\admin\model\SystemConfig;
use app\api\model\MallGoods;
use app\api\model\MallUser;

class V
{
    public static function run($param)
    {
        $userId  = $param[ 'userId' ];
        $goodsId = _checkEmptyParam($param[ 'goodsId' ], '用户ID不能为空');
        $goods   = MallGoods::with([
            'spec' => function ($query) {
                $query->where('delete_time', '=', null);
            },
        ])
            ->where([['id', '=', $goodsId]])
            ->field('id,title,logo,images,market_price,discount_price,novice_price,failure_reward,success_reward,virtual_sales,describe,collage_num+1 as collage_num,is_novices_exclusive')
            ->find();
        if (empty($goods)) {
            _outPut(201, [], '商品不存在');
        }
//        $goods[ 'is_novice' ]      = MallUser::where('id', $userId)->value('is_novice');
//        if ($goods['is_novices_exclusive']==1&&$goods['is_novice']!=1){
//            _outPut(201, [], '该商品只允许新手购买');
//        }
        $goods                     = $goods->toArray();
        $goods[ 'market_price' ]   = getPrice($goods[ 'market_price' ]);
        $goods[ 'discount_price' ] = getPrice($goods[ 'discount_price' ]);
        $goods[ 'novice_price' ]   = getPrice($goods[ 'novice_price' ]);
        $goods[ 'failure_reward' ] = getPrice($goods[ 'failure_reward' ]);
        $goods[ 'success_reward' ] = getPrice($goods[ 'success_reward' ]);
        $goods[ 'is_novice' ]      = MallUser::where('id', $userId)->value('is_novice') ?? 0;
        _outPut(200, $goods);
    }
}